# For replication purposes, this file was extracted from a qmd file (of the same name) that produces the entire paper.
# It outputs figures 2-5 from the paper as pdfs in the output/ directory.
# It also contains the code for all of the tables and figures in the appendix (though these are not output by this file, because that would require a lot more manual tinkering).
# We are including the qmd file in the replication package, which should resolve any questions about what code produced what numbers.


## -----------------------------------------------------------------------------
#| echo: false
#| message: false
library(tidyverse)
load("data/D_and_D_post_exclusions_v2.RData") # see ssi_2024_construct_analysis_data.qmd



## ----exclusion-numbers--------------------------------------------------------
D |> 
  group_by(Condition) |> 
  mutate(outlier = log(`Duration (in seconds)`) > quantile(log(`Duration (in seconds)`), .75) + 1.5*IQR(log(`Duration (in seconds)`)) | log(`Duration (in seconds)`) < quantile(log(`Duration (in seconds)`), .25) - 1.5*IQR(log(`Duration (in seconds)`))) -> D_with_outliers 

number_of_outliers <- D_with_outliers |> ungroup() |> summarize(sum(outlier)) |> as.numeric()

D_with_outliers |>
  filter(!outlier) |> 
  mutate(attention_check_status = case_when(attention_check == "Strongly disagree,Neither agree nor disagree" ~ "Passed",
                                            !str_detect(attention_check, "\\,") ~ "Failed: single response",
                                            TRUE ~ "Failed: more than one response")) -> D_woo_ac_coded

number_of_inattentives <- D_woo_ac_coded |> ungroup() |> summarize(sum(attention_check_status != "Passed"))


## ----spi-regs-----------------------------------------------------------------
#| echo: false

spi_reg_list_given_data <- function(this_data = D_post_exclusions){
  spi_SAI <- estimatr::lm_robust(standardized_policy_index ~ SAI_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)

  spi_Emissions <- estimatr::lm_robust(standardized_policy_index ~ Emissions_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)

  spi_all_four <- estimatr::lm_robust(standardized_policy_index ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  
  list(spi_SAI, spi_Emissions, spi_all_four)

}

spi_reg_list_wo_exclusions <- spi_reg_list_given_data(D)


## -----------------------------------------------------------------------------

spi_reg_results_wo_exclusions <- rbind(
  spi_reg_list_wo_exclusions[[1]] |> estimatr::tidy() |> filter(term =="SAI_either") |> 
    mutate(Model ="1"), 
  spi_reg_list_wo_exclusions[[2]] |> estimatr::tidy() |> filter(term =="Emissions_either") |> 
    mutate(Model = "2"), 
    spi_reg_list_wo_exclusions[[3]] |> estimatr::tidy() |> filter(str_detect(term, "Condition")) |> 
    mutate(Model ="3"))

df <- spi_reg_results_wo_exclusions


df <- df |>
  mutate(term = recode(term,
    "SAI_either"           = "Provided SAI info",
    "Emissions_either"     = "Provided decarbonization info",
    "ConditionEmissions"   = "Provided decarbonization info only",
    "ConditionSAI"         = "Provided SAI info only",
    "ConditionBoth"        = "Provided both SAI and decarbonization info"
  ))


df <- df |>
  mutate(order = case_when(
    term == "Provided SAI info"                   ~ 3.7,
    term == "Provided decarbonization info"         ~ 2.7,
    term == "Provided decarbonization info only"    ~ 1.6,
    term == "Provided SAI info only"                ~ 1.3,
    term == "Provided both SAI and decarbonization info" ~ 1
  ))


plt <- ggplot(df, aes(x = estimate, y = order, color = Model, shape = Model)) +
  geom_vline(xintercept = 0, color = "gray50", linetype = 2) +
  geom_errorbarh(aes(xmin = conf.low, xmax = conf.high), height = 0.2) +
  geom_point(size = 3, fill = "white") +
  scale_color_manual(values = c("1" = "#3B9AB2", "2" = "#E1AF00", "3" = "#F98400")) +
  # Use the order variable for the y-axis and assign the recoded term labels
  scale_y_continuous(breaks = df$order,
                     labels = df$term,
                     expand = expansion(mult = c(0.1, 0.1))) +
  labs(x = "Estimates with 95% Confidence Intervals",
       y = "") +
  # theme(text = element_text(size = 10.5, family = "CMU Concrete"),
  #       axis.title = element_text(family = "CMU Concrete"),
  #       plot.title = element_text(family = "CMU Concrete"),
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"))


## -----------------------------------------------------------------------------
#| echo: false
#| fig-width: 6
#| fig-height: 4
#| label: fig-main-results
#| fig-cap: "Effect of information treatments on support for emission reduction policies"

## FIGURE 2
plt
ggsave("output/fig-main-results-1.pdf", width = 6, height = 4)


## -----------------------------------------------------------------------------
# compute $p$-values for other comparisons
get_the_variance_for_a_diff <- function(mod, var1, var2){
  vc <- vcov(mod)[c(var1, var2), c(var1, var2)]
  vc[1,1] + vc[2,2] - 2*vc[1,2]
}
# get_the_variance(swi_condition, "ConditionBoth", "ConditionSAI")
get_the_p_for_a_diff <- function(mod, var1, var2){
  v <- get_the_variance_for_a_diff(mod, var1, var2)
  diff <- coef(mod)[var1] - coef(mod)[var2]
  as.numeric(2*(1 - pnorm(abs(diff)/sqrt(v))))
}
# get_the_p_for_a_diff(swi_condition, "ConditionBoth", "ConditionSAI")
# get_the_p_for_a_diff(swi_condition, "ConditionBoth", "ConditionSAI")


## ----main-effect-heterogeneity------------------------------------------------
#| echo: false

spi_het_reg_list_given_data <- function(this_data){
  spi_SAI_by_affiliation <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*I(Affiliation %in% c("Very liberal", "Liberal")) + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  spi_SAI_by_concern <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*I(cc_concern_pre %in% c("Not concerned at all", "Slightly concerned")) + Affiliation + attribution_quintile + self_efficacy_pre, data = this_data)
  spi_SAI_by_attribution <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*I(attribution_quintile %in% c(1, 2)) + Affiliation + cc_concern_pre + self_efficacy_pre, data = this_data)

  list("By ideology" = spi_SAI_by_affiliation, "By concern" = spi_SAI_by_concern, "By attribution" = spi_SAI_by_attribution)
}
het_reg_table_given_reg_list <- function(reg_list){
  rows <- tribble(~term, ~term, ~term, ~term,
                 "Covariates", "Yes", "Yes", "Yes")
  attr(rows, "position") <- 17 # put it at the bottom

  modelsummary::modelsummary(reg_list, 
                           stars = T, 
                           gof_map = c("nobs", "r.squared", "adj.r.squared"), 
                           coef_map = c("(Intercept)" = "Intercept", 
                                        "SAI_either" = "Provided SAI info", 
                                        'I(Affiliation %in% c("Very liberal", "Liberal"))TRUE' = "Liberal",
                                        'SAI_either:I(Affiliation %in% c("Very liberal", "Liberal"))TRUE' = "SAI info X Liberal",
                                        'I(cc_concern_pre %in% c("Not concerned at all", "Slightly concerned"))TRUE' = "Less concerned about global warming", 
                                        'SAI_either:I(cc_concern_pre %in% c("Not concerned at all", "Slightly concerned"))TRUE' = "SAI info X Less concerned",
                                        "I(attribution_quintile %in% c(1, 2))TRUE" = "Attributes less to human action", 
                                        "SAI_either:I(attribution_quintile %in% c(1, 2))TRUE" = "SAI info X Attributes less to human action"), 
                           add_rows = rows) |>
  tinytable::group_tt(j = list("DV: Index of support for mitigation policy" = 2:4))
}

spi_het_reg_list_wo_exclusions <- spi_het_reg_list_given_data(D)



## -----------------------------------------------------------------------------

get_the_variance_for_a_sum <- function(mod, var1, var2){
  vc <- vcov(mod)[c(var1, var2), c(var1, var2)]
  vc[1,1] + vc[2,2] + 2*vc[1,2]
}
spi_het_reg_results_wo_exclusions <- rbind(
  spi_het_reg_list_wo_exclusions[[1]] |> estimatr::tidy() |> mutate(Model = "1"), 
  spi_het_reg_list_wo_exclusions[[2]] |> estimatr::tidy() |> mutate(Model = "2"), 
  spi_het_reg_list_wo_exclusions[[3]] |> estimatr::tidy() |> mutate(Model = "3")
) |>
  # Filter to only the terms we want to recode
  filter(term %in% c(
    "SAI_either", 
    'SAI_either:I(Affiliation %in% c("Very liberal", "Liberal"))TRUE', 
    'SAI_either:I(cc_concern_pre %in% c("Not concerned at all", "Slightly concerned"))TRUE', 
    "SAI_either:I(attribution_quintile %in% c(1, 2))TRUE"
  )) 

  
spi_het_reg_results_wo_exclusions[spi_het_reg_results_wo_exclusions$term =='SAI_either:I(Affiliation %in% c("Very liberal", "Liberal"))TRUE' & spi_het_reg_results_wo_exclusions$Model == "1","estimate"]  = spi_het_reg_results_wo_exclusions[
  spi_het_reg_results_wo_exclusions$term =='SAI_either:I(Affiliation %in% c("Very liberal", "Liberal"))TRUE'& spi_het_reg_results_wo_exclusions$Model == "1","estimate"] + 
  spi_het_reg_results_wo_exclusions[spi_het_reg_results_wo_exclusions$term =="SAI_either"& spi_het_reg_results_wo_exclusions$Model == "1","estimate"]

spi_het_reg_results_wo_exclusions[spi_het_reg_results_wo_exclusions$term =='SAI_either:I(cc_concern_pre %in% c("Not concerned at all", "Slightly concerned"))TRUE'& spi_het_reg_results_wo_exclusions$Model == '2','estimate']  = spi_het_reg_results_wo_exclusions[
  spi_het_reg_results_wo_exclusions$term =='SAI_either:I(cc_concern_pre %in% c("Not concerned at all", "Slightly concerned"))TRUE'& spi_het_reg_results_wo_exclusions$Model == '2','estimate'] + 
  spi_het_reg_results_wo_exclusions[spi_het_reg_results_wo_exclusions$term =='SAI_either'& spi_het_reg_results_wo_exclusions$Model == '2','estimate']

spi_het_reg_results_wo_exclusions[spi_het_reg_results_wo_exclusions$term =='SAI_either:I(attribution_quintile %in% c(1, 2))TRUE'& spi_het_reg_results_wo_exclusions$Model == '3','estimate']  = spi_het_reg_results_wo_exclusions[
  spi_het_reg_results_wo_exclusions$term =='SAI_either:I(attribution_quintile %in% c(1, 2))TRUE'& spi_het_reg_results_wo_exclusions$Model == '3','estimate'] + 
  spi_het_reg_results_wo_exclusions[spi_het_reg_results_wo_exclusions$term =='SAI_either'& spi_het_reg_results_wo_exclusions$Model == '3','estimate']


z_stat = qnorm(0.975)

mod1 <- spi_het_reg_list_wo_exclusions[[1]]
recoded_term1 <- 'SAI_either:I(Affiliation %in% c("Very liberal", "Liberal"))TRUE'
base_term <- "SAI_either"

# compute the variance of the difference between base and recoded term
new_var1 <- get_the_variance_for_a_sum(mod1, base_term, recoded_term1)
new_se1 <- sqrt(new_var1)

# update the standard error and 95% confidence interval in the results data frame
idx1 <- spi_het_reg_results_wo_exclusions$Model == "1" & 
        spi_het_reg_results_wo_exclusions$term == recoded_term1

spi_het_reg_results_wo_exclusions[idx1, "std.error"] <- new_se1
spi_het_reg_results_wo_exclusions[idx1, "conf.low"] <- 
  spi_het_reg_results_wo_exclusions[idx1, "estimate"] - z_stat * new_se1
spi_het_reg_results_wo_exclusions[idx1, "conf.high"] <- 
  spi_het_reg_results_wo_exclusions[idx1, "estimate"] + z_stat * new_se1

# For Model 2
mod2 <- spi_het_reg_list_wo_exclusions[[2]]
recoded_term2 <- 'SAI_either:I(cc_concern_pre %in% c("Not concerned at all", "Slightly concerned"))TRUE'
base_term <- "SAI_either"

new_var2 <- get_the_variance_for_a_sum(mod2, base_term, recoded_term2)
new_se2 <- sqrt(new_var2)

idx2 <- spi_het_reg_results_wo_exclusions$Model == "2" & 
        spi_het_reg_results_wo_exclusions$term == recoded_term2

spi_het_reg_results_wo_exclusions[idx2, "std.error"] <- new_se2
spi_het_reg_results_wo_exclusions[idx2, "conf.low"] <- 
  spi_het_reg_results_wo_exclusions[idx2, "estimate"] - z_stat * new_se2
spi_het_reg_results_wo_exclusions[idx2, "conf.high"] <- 
  spi_het_reg_results_wo_exclusions[idx2, "estimate"] + z_stat * new_se2

# For Model 3
mod3 <- spi_het_reg_list_wo_exclusions[[3]]
recoded_term3 <- 'SAI_either:I(attribution_quintile %in% c(1, 2))TRUE'
base_term <- "SAI_either"

new_var3 <- get_the_variance_for_a_sum(mod3, base_term, recoded_term3)
new_se3 <- sqrt(new_var3)

idx3 <- spi_het_reg_results_wo_exclusions$Model == "3" & 
        spi_het_reg_results_wo_exclusions$term == recoded_term3

spi_het_reg_results_wo_exclusions[idx3, "std.error"] <- new_se3
spi_het_reg_results_wo_exclusions[idx3, "conf.low"] <- 
  spi_het_reg_results_wo_exclusions[idx3, "estimate"] - z_stat * new_se3
spi_het_reg_results_wo_exclusions[idx3, "conf.high"] <- 
  spi_het_reg_results_wo_exclusions[idx3, "estimate"] + z_stat * new_se3

df_het <- spi_het_reg_results_wo_exclusions |> 
  # Recode the term names
  mutate(term = case_when(
    term == "SAI_either" & Model =="1" ~ "Provided SAI info (not liberal)", 
    term == 'SAI_either:I(Affiliation %in% c("Very liberal", "Liberal"))TRUE' ~ "Provided SAI info (liberal)",
    term == "SAI_either" & Model =="2" ~ "Provided SAI info (more concerned)", 
    term == 'SAI_either:I(cc_concern_pre %in% c("Not concerned at all", "Slightly concerned"))TRUE' ~ "Provided SAI info (less concerned)",
    term == "SAI_either" & Model =="3" ~ "Provided SAI info\n(Attributes more to human action)",
    term == "SAI_either:I(attribution_quintile %in% c(1, 2))TRUE" ~ "Provided SAI info\n(Attributes less to human action)",
    TRUE ~ term
  )) |> 
  mutate(order = case_when(
    Model == "1" & term == "Provided SAI info (not liberal)" ~ 5.6,
    Model == "1" & term == "Provided SAI info (liberal)" ~ 5.2,
    Model == "2" & term == "Provided SAI info (more concerned)" ~ 3.6,
    Model == "2" & term == "Provided SAI info (less concerned)" ~ 3.2,
    Model == "3" & term == "Provided SAI info\n(Attributes more to human action)" ~ 1.6,
    Model == "3" & term == "Provided SAI info\n(Attributes less to human action)" ~ 1,
    TRUE ~ NA_real_
  )) 

plt_het <- ggplot(df_het, aes(x = estimate, y = order, color = Model, shape = Model)) +
  geom_vline(xintercept = 0, color = "gray50", linetype = 2) +
  geom_errorbarh(aes(xmin = conf.low, xmax = conf.high), height = 0.2) +
  geom_point(size = 3, fill = "white") +
  scale_color_manual(values = c("1" = "#3B9AB2", "2" = "#E1AF00", "3" = "#F98400")) +
  scale_y_continuous(breaks = df_het$order,
                     labels = df_het$term,
                     expand = expansion(mult = c(0.1, 0.1))) +
  labs(x = "Estimates with 95% Confidence Intervals",
       y = "") +
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"))


## -----------------------------------------------------------------------------
#| echo: false
#| fig-width: 6
#| fig-height: 4
#| label: fig-het-main
#| fig-cap: "Heterogeneity in effect of SAI information on support for emission reduction policies"

## FIGURE 3
plt_het
ggsave("output/fig-het-main-1.pdf", width = 6, height = 4)


## ----main-mechanisms----------------------------------------------------------
other_attitudes_reg_list <- function(this_data){
  # SWI: standardized worry index
  swi_SAI <- estimatr::lm_robust(standardized_worry_index ~ SAI_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  # STT: standardized tech threat
  stt_SAI <- estimatr::lm_robust(standardized_tech_threat ~ SAI_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  # STT: standardized mech belief
  smb_SAI <- estimatr::lm_robust(standardized_mech_belief ~ SAI_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  # STT: standardized techno fix
  stf_SAI <- estimatr::lm_robust(standardized_techno_fix ~ SAI_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  
  list("DV: Worry about climate change" = swi_SAI, "DV: Perceived techno threat" = stt_SAI, "DV: Belief in efficacy of emissions reductions" = smb_SAI, "DV: Belief in techno fix" = stf_SAI)
}

other_attitudes_table_from_reg_list <- function(reg_list){
  # adding a row to say: yes we have covariates
  rows <- tribble(~term, ~term, ~term, ~term, ~term, 
               "Covariates", "Yes", "Yes", "Yes", "Yes")
  attr(rows, "position") <- 5 # put it at the bottom

  modelsummary::modelsummary(reg_list, stars = T, gof_map = c("nobs", "r.squared", "adj.r.squared"), coef_map = c("(Intercept)" = "Intercept", "SAI_either" = "Provided SAI info"), add_rows = rows,
                           width = c(2,1,1,1,1))
}

other_attitudes_rl <- other_attitudes_reg_list(D)


## -----------------------------------------------------------------------------

other_attitudes_rl_bind <- rbind(
  other_attitudes_rl[[1]] |> estimatr::tidy() |> 
    mutate(term = case_when(term == "SAI_either" ~ "DV: Worry about climate change",
                            TRUE ~ term)), 
  other_attitudes_rl[[2]] |> estimatr::tidy() |> 
    mutate(term = case_when(term == "SAI_either" ~ "DV: Perceived techno threat",
                            TRUE ~ term)), 
  other_attitudes_rl[[3]] |> estimatr::tidy() |> 
    mutate(term = case_when(term == "SAI_either" ~ "DV: Belief in efficacy of\nemissions reductions",
                            TRUE ~ term)), 
    other_attitudes_rl[[4]] |> estimatr::tidy() |> 
    mutate(term = case_when(term == "SAI_either" ~ "DV: Belief in techno fix",
                            TRUE ~ term))) |> 
  filter(stringr::str_detect(term, "DV:"))

# reorder factors in term
other_attitudes_rl_bind$term = factor(other_attitudes_rl_bind$term, 
                                      levels = rev(c(
                                        "DV: Worry about climate change",
                                        "DV: Perceived techno threat",
                                        "DV: Belief in efficacy of\nemissions reductions",
                                        "DV: Belief in techno fix"
                                      )))
  

plt_other_attitudes <- ggplot(other_attitudes_rl_bind, aes(x = estimate, y = term)) +
  geom_vline(xintercept = 0, color = "gray50", linetype = 2) +
  geom_errorbarh(aes(xmin = conf.low, xmax = conf.high), height = 0.2) +
  geom_point(size = 3, fill = "white") +
  scale_y_discrete(#breaks = other_attitudes_rl_bind$order,
                     #labels = other_attitudes_rl_bind$term,
                     expand = expansion(mult = c(0.1, 0.1))) +
  labs(x = "Estimates with 95% Confidence Intervals",
       y = "") +
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"))


## -----------------------------------------------------------------------------
#| echo: false
#| fig-width: 6
#| fig-height: 3
#| label: fig-sai-on-other-outcomes
#| fig-cap: "Effect of SAI information on other attitudes"

## FIGURE 4
plt_other_attitudes
ggsave("output/fig-sai-on-other-outcomes-1.pdf", width = 6, height = 3)


## ----other4-funcs-------------------------------------------------------------
reg_list_other_outcomes4 <- function(this_data){
  swi_condition <- estimatr::lm_robust(standardized_worry_index ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  stt_condition <- estimatr::lm_robust(standardized_tech_threat ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  smb_condition <- estimatr::lm_robust(standardized_mech_belief ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  stf_condition <- estimatr::lm_robust(standardized_techno_fix ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = this_data)
  
  list("DV: Worry about climate change" = swi_condition, "DV: Perceived techno threat" = stt_condition, "DV: Belief in efficacy of emissions reductions" = smb_condition, "DV: Belief in techno fix" = stf_condition)
}

table_for_other_outcomes4 <- function(reg_list){
  rows <- tribble(~term, ~term, ~term, ~term, ~term, 
               "Covariates", "Yes", "Yes", "Yes", "Yes")
  attr(rows, "position") <- 9 # put it at the bottom

  modelsummary::modelsummary(reg_list, stars = T, gof_map = c("nobs", "r.squared", "adj.r.squared"), coef_map = c("(Intercept)" = "Intercept", "ConditionSAI" = "Provided SAI info only", "ConditionEmissions" = "Provided decarbonization info only", "ConditionBoth" = "Provided both"), add_rows = rows,
                           width = c(6,2,2,2,2))
}
reg_list_other4 <- reg_list_other_outcomes4(D)


## -----------------------------------------------------------------------------

reg_list_other4_bind <- rbind(
  reg_list_other4[[1]] |> estimatr::tidy() |> 
    mutate(model =  "DV: Worry about climate change"),
  reg_list_other4[[2]] |> estimatr::tidy() |> 
    mutate(model = "DV: Perceived techno threat"),
  reg_list_other4[[3]] |> estimatr::tidy() |> 
    mutate(model =  "DV: Belief in efficacy of\nemissions reductions"),
    reg_list_other4[[4]] |> estimatr::tidy() |> 
    mutate(model = "DV: Belief in techno fix")) |> 
  filter(stringr::str_detect(term, "Condition")) |> 
  mutate(term = recode(term,
    "ConditionEmissions"   = "Provided decarbonization info only",
    "ConditionSAI"         = "Provided SAI info only",
    "ConditionBoth"        = "Provided both"
  ), 
    term = factor(term, levels = c(
      "Provided decarbonization info only",
      "Provided SAI info only",
      "Provided both")))



reg_list_other4_bind$model = factor(reg_list_other4_bind$model, 
                                      levels = rev(c(
                                        "DV: Worry about climate change",
                                        "DV: Perceived techno threat",
                                        "DV: Belief in efficacy of\nemissions reductions",
                                        "DV: Belief in techno fix"
                                      )))

# Plot the results using a horizontal error bar and custom y-axis ordering.
plt_other4 <- reg_list_other4_bind |> 
  ggplot(aes(x = estimate, xmin = conf.low, xmax = conf.high, y = model, col = term, pch = term)) + 
  geom_pointrange(position = position_dodge(width = -.35)) + 
  geom_vline(xintercept = 0, lty = 3) + 
  scale_y_discrete() +
  scale_color_manual(values = c("Provided decarbonization info only" = "#3B9AB2", 
                                "Provided SAI info only" = "#E1AF00", 
                                "Provided both" = "#F98400")) +
  guides(color = guide_legend(nrow = 2, byrow = TRUE))+
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black")) +
  labs(x = "Estimates with 95% Confidence Intervals", y = "", pch = "", col = "")



## -----------------------------------------------------------------------------
#| echo: false
#| fig-width: 6.3
#| fig-height: 4.2
#| label: fig-other-outcomes-by-treatment-arm
#| fig-cap: "Effect of each information treatment on other attitudes"

## FIGURE 5
plt_other4
ggsave("output/fig-other-outcomes-by-treatment-arm-1.pdf", width = 6.3, height = 4.2)


## -----------------------------------------------------------------------------
#| echo: false
both_vs_emissions_p <- get_the_p_for_a_diff(reg_list_other4[["DV: Belief in efficacy of emissions reductions"]], "ConditionBoth", "ConditionEmissions")


## -----------------------------------------------------------------------------
#| echo: false
#| message: false
#| warning: false
#| fig-width: 6
#| fig-height: 4
#| label: fig-power
#| fig-cap: "Power curves for detecting effect sizes at different sample sizes"

results <- tibble(x = seq(0, .2, by = .001)) %>% 
  expand_grid(n = c(200, 1000, 1500, 2500),
              C = 0.7,
              groups = 4) %>% 
  mutate(se_n = sqrt(2 * groups * C / n),
         power = 1 - pnorm(qnorm(0.975) * se_n, mean = x, sd = se_n),
         sample = factor(n)) %>% 
  mutate(
    C_label      = paste0("Variance factor: ", C),
    groups_label = paste0("Number of groups: ", groups)
  )

color_vals    <- c("200" = "#3B9AB2", "1000" = "#E1AF00", "1500" = "#F98400", "2500" = "#A3A500")
linetype_vals <- c("200" = "solid",   "1000" = "dashed",   "1500" = "dotted",  "2500" = "twodash")

ggplot(results, aes(x = x, y = power, color = sample, linetype = sample)) +
  geom_vline(xintercept = 0.15, color = "gray50", linetype = 2) +
  geom_hline(yintercept = c(0.05, 0.8), color = "gray50", linetype = 3) +
  geom_line(size = 1) +
  scale_color_manual(name = "Sample size", values = color_vals) +
  scale_linetype_manual(name = "Sample size", values = linetype_vals) +
  expand_limits(y = 0) +
  labs(
    x   = "Effect size (in SDs of outcome)",
    y   = "Power"
  ) +
  theme(
    legend.position      = "top",
    legend.key           = element_blank(),
    panel.background     = element_blank(),
    panel.grid.major     = element_blank(),
    panel.grid.minor     = element_blank(),
    axis.line            = element_line(color = "black"),
    axis.text            = element_text(color = "black"),
    text                 = element_text(size = 11)
  )


## -----------------------------------------------------------------------------
#| echo: false
#| output: false
sample_proportions <- D |> 
  mutate(White = Race == "White",
         Black = Race == "Black or African American",
         Asian = Race %in% c("Chinese", "Filipino", "Japanese", "Asian Indian", "Vietnamese", "Korean"),
         `American Indian or Alaska Native` = Race == "American Indian or Alaska Native",
         `Other race` = Race %in% c("An ethnicity not listed here", "Other"),
         Male = Sex == "Male",
         Female = Sex == "Female",
         `Age 18-29` = Age >= 18 & Age <= 29,
         `Age 30-39` = Age >= 30 & Age <= 39,
         `Age 40-49` = Age >= 40 & Age <= 49,
         `Age 50-59` = Age >= 50 & Age <= 59,
         `Age 60-69` = Age >= 60 & Age <= 69,
         `Age 70+` = Age >= 70,
         `High school` = str_detect(Education, "^High school graduate"),
         `Some college` = str_detect(Education, "^Some college"),
         `Associates degree` = str_detect(Education, "^Associate degree"),
         `Bachelors degree` = str_detect(Education, "^Bachelor"),
         `Masters degree` = str_detect(Education, "^Master"),
         `Doctorate` = str_detect(Education, "^Doctorate"),
         `HH income < $10k` = `Household Income` == "Less than $10,000",
         `HH income $10k-$20k` = `Household Income` == "$10,000-$19,999",
         `HH income $20k-$30k` = `Household Income` == "$20,000-$29,999",
         `HH income $30k-$40k` = `Household Income` == "$30,000-$39,999",
         `HH income $40k-$50k` = `Household Income` == "$40,000-$49,999",
         `HH income $50k-$60k` = `Household Income` == "$50,000-$59,999",
         `HH income $60k-$70k` = `Household Income` == "$60,000-$69,999",
         `HH income $70k-$80k` = `Household Income` == "$70,000-$79,999",
         `HH income $80k-$90k` = `Household Income` == "$80,000-$89,999",
         `HH income $90k-$100k` = `Household Income` == "$90,000-$99,999",
         `HH income $100k-$125k` = `Household Income` == "$100,000-$124,999",
         `HH income $125k-$150k` = `Household Income` == "$125,000-$149,999",
         `HH income $150k-$175k` = `Household Income` == "$150,0000-$174,999",
         `HH income $175k-$200k` = `Household Income` == "$175,000-$199,999",
         `HH income $200k+` = `Household Income` %in% c("$200,000-$224,999",
                                                        "$225,000-$249,999",
                                                        "$250,000 or more"),
         Democrat = `Political Party` == "Democrat",
         Republican = `Political Party` == "Republican",
         Independent = `Political Party` == "Independent",
         `Other party` = `Political Party` == "Something else") |> 
  summarize(across(White:`Other party`, ~ mean(.x, na.rm = T))) |> 
  pivot_longer(cols = everything(), names_to = "Characteristic", values_to = "Sample")

population_proportions <- tribble(~Characteristic, ~Population,
                           "Age 18-29", .2, 
                           "Age 30-39", .18,
                           "Age 40-49", .16,
                           "Age 50-59", .16,
                           "Age 60-69", .16,
                           "Age 70+", .15,
                           "High school", .29,
                           "Some college", .16,
                           "Associates degree", .1,
                           "Bachelors degree", .22,
                           "Masters degree", .09,
                           "Doctorate", .02,
                           "HH income < $10k", .03, 
                           "HH income $10k-$20k", .04,
                           "HH income $20k-$30k", .05,
                           "HH income $30k-$40k", .06,
                           "HH income $40k-$50k", .06,
                           "HH income $50k-$60k", .06, 
                           "HH income $60k-$70k", .06,
                           "HH income $70k-$80k", .06,
                           "HH income $80k-$90k", .05,
                           "HH income $90k-$100k", .05,
                           "HH income $100k-$125k", .11,
                           "HH income $125k-$150k", .08,
                           "HH income $150k-$175k", .07,
                           "HH income $175k-$200k", .05,
                           "HH income $200k+", .16,
                           "White", .755,
                           "Black", .136,
                           "Asian", .063,
                           "American Indian or Alaska Native", .016,
                           "Other race",  .03, 
                           "Male", .496,
                           "Female", .504,
                           "Democrat", .28,
                           "Republican", .3,
                           "Independent", .41,
                           "Other party", .01)

population_proportions |> 
  left_join(sample_proportions) -> joined_proportions


## -----------------------------------------------------------------------------
#| echo: false
#| fig-height: 6
#| fig-width: 5.5
#| fig-cap: "Comparison of analysis sample to US population. Data on US population from the US Census and (for party affiliation) a March 2024 Gallup poll"
#| label: fig-rep
joined_proportions |> 
  pivot_longer(cols = -Characteristic, names_to = "Type") |> 
  mutate(Characteristic = fct_inorder(Characteristic)) |> 
  ggplot(aes(x = value, y = fct_rev(Characteristic), col = Type)) + 
  geom_point(alpha = .7) + 
  geom_line(aes(group = Characteristic), show.legend = F) + 
  labs(x = "Proportion", y = "", col = "") + 
  scale_color_manual(values = c("Population" = "#3B9AB2", "Sample" = "#E1AF00")) +
  #theme_bw() + 
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"))



## -----------------------------------------------------------------------------
#| echo: false
#| message: false
#| fig-cap: "Manipulation check: proportion saying each technology is viewed as promising by some experts, separately by treatment group"
#| label: fig-manip-check
D |> 
  select(Condition, starts_with("manip_check")) |> 
  pivot_longer(-Condition, names_to = "Question", names_prefix = "manip_check_post_2_") |> 
  left_join(tibble(Question = c("1", "2", "3", "4"), Technology = c('Extracting silicates from\nagricultural soil', 'Releasing sulfur dioxide\ninto the atmosphere', "Pumping dry ice into\nthe earth's crust", 'Converting heating systems\nto use electricity\ninstead of gas')), by = "Question") |> 
  group_by(Condition, Technology) |> 
  summarize(pr_promising = mean(value == "Some experts view as promising")) |> 
  ggplot(aes(x = Technology, y = pr_promising, col = Condition)) + 
  geom_point() + 
  coord_flip() + 
  labs(y = "Proportion saying some experts\nview given technology as promising") + 
  scale_color_manual(values = c("Neither" = "#3B9AB2", "Emissions" = "#E1AF00", "SAI" = "#FF0000",
                                "Both" = "#D5D5D3")) +
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"))
  


## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-manip-check
#| tbl-cap: "Manipulation check regression results"

manip_1 <- estimatr::lm_robust(I(manip_check_post_2_1 == "Some experts view as promising") ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

manip_2 <- estimatr::lm_robust(I(manip_check_post_2_2 == "Some experts view as promising") ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

manip_3 <- estimatr::lm_robust(I(manip_check_post_2_3 == "Some experts view as promising") ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

manip_4 <- estimatr::lm_robust(I(manip_check_post_2_4 == "Some experts view as promising") ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

# adding a row to say: yes we have covariates
rows <- tribble(~term, ~term, ~term,  ~term, ~term,  
               "Covariates", "Yes", "Yes", "Yes", "Yes") 
attr(rows, "position") <- 9 # put it at the bottom

modelsummary::modelsummary(list("Extract silicates from agricultural soil" = manip_1, 
                                "Release sulfur dioxide into the atmosphere" = manip_2, 
                                "Pump dry ice into the earth's crust" = manip_3, 
                                "Convert heating systems to use electricity instead of gas" = manip_4), 
                           stars = T, 
                           gof_map = c("nobs", "r.squared", "adj.r.squared"),
                           coef_map = c("(Intercept)" = "Intercept",
                                        "ConditionSAI" = "SAI info only", 
                                        "ConditionEmissions" = "Emissions info only", 
                                        "ConditionBoth" = "SAI and emission info"), 
                           add_rows = rows,
                           # width and theme arguments passed to tinytable::tt
                           width = c(5,3,3,3,3)) -> xx

xx |> 
  tinytable::group_tt(j = list("DV: Stated technology seen as promising" = 2:5))
  


## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-main-results
#| tbl-cap: "Effect of information treatments on support for emission reduction policies"

main_result_table_from_reg_list <- function(reg_list){
  # adding a row to say: yes we have covariates
  rows <- tribble(~term, ~term, ~term, ~term, 
               "Covariates", "Yes", "Yes", "Yes")
  attr(rows, "position") <- 13 # put it at the bottom

  modelsummary::modelsummary(reg_list, 
                           stars = T, 
                           gof_map = c("nobs", "r.squared", "adj.r.squared"), 
                           coef_map = c("(Intercept)" = "Intercept", 
                                        "SAI_either" = "Provided SAI info", 
                                        "Emissions_either" = "Provided decarbonization info", 
                                        "ConditionSAI" = "Provided SAI info only", 
                                        "ConditionEmissions" = "Provided decarbonization info only", 
                                        "ConditionBoth" = "Provided both SAI and decarbonization info"), 
                           add_rows = rows,
                           width = c(4,1,1,1)) |> 
  tinytable::group_tt(j = list("DV: Index of support for mitigation policy" = 2:4))
}

main_result_table_from_reg_list(spi_reg_list_wo_exclusions)



## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-main-results-weighted
#| tbl-cap: "Effect of information treatments on support for emission reduction policies with sample weighted to align with population characteristics"

library(survey)

D_clean <- D |>
  mutate(
    # Recode Age groups
    Age_group = case_when(
      Age >= 18 & Age <= 29 ~ "Age 18-29",
      Age >= 30 & Age <= 39 ~ "Age 30-39",
      Age >= 40 & Age <= 49 ~ "Age 40-49",
      Age >= 50 & Age <= 59 ~ "Age 50-59",
      Age >= 60 & Age <= 69 ~ "Age 60-69",
      Age >= 70           ~ "Age 70+",
      TRUE ~ NA_character_
    ),
    # Recode Education
    Education_recode = case_when(
      str_detect(Education, "^High school graduate") ~ "High school",
      str_detect(Education, "^Some college") ~ "Some college",
      str_detect(Education, "^Associate degree") ~ "Associates degree",
      str_detect(Education, "^Bachelor") ~ "Bachelors degree",
      str_detect(Education, "^Master") ~ "Masters degree",
      str_detect(Education, "^Doctorate") ~ "Doctorate",
      TRUE ~ NA_character_
    ),
    # Recode Household Income
    Income_group = case_when(
      `Household Income` == "Less than $10,000" ~ "HH income < $10k",
      `Household Income` == "$10,000-$19,999" ~ "HH income $10k-$20k",
      `Household Income` == "$20,000-$29,999" ~ "HH income $20k-$30k",
      `Household Income` == "$30,000-$39,999" ~ "HH income $30k-$40k",
      `Household Income` == "$40,000-$49,999" ~ "HH income $40k-$50k",
      `Household Income` == "$50,000-$59,999" ~ "HH income $50k-$60k",
      `Household Income` == "$60,000-$69,999" ~ "HH income $60k-$70k",
      `Household Income` == "$70,000-$79,999" ~ "HH income $70k-$80k",
      `Household Income` == "$80,000-$89,999" ~ "HH income $80k-$90k",
      `Household Income` == "$90,000-$99,999" ~ "HH income $90k-$100k",
      `Household Income` == "$100,000-$124,999" ~ "HH income $100k-$125k",
      `Household Income` == "$125,000-$149,999" ~ "HH income $125k-$150k",
      `Household Income` == "$150,0000-$174,999" ~ "HH income $150k-$175k",
      `Household Income` == "$175,000-$199,999" ~ "HH income $175k-$200k",
      `Household Income` %in% c("$200,000-$224,999", "$225,000-$249,999", "$250,000 or more") ~ "HH income $200k+",
      TRUE ~ NA_character_
    ),
    # Recode Race
    Race_recode = case_when(
      Race == "White" ~ "White",
      Race == "Black or African American" ~ "Black",
      Race %in% c("Chinese", "Filipino", "Japanese", "Asian Indian", "Vietnamese", "Korean") ~ "Asian",
      Race == "American Indian or Alaska Native" ~ "American Indian or Alaska Native",
      Race %in% c("An ethnicity not listed here", "Other") ~ "Other race",
      TRUE ~ NA_character_
    ),
    # Recode Sex
    Sex_recode = case_when(
      Sex == "Male" ~ "Male",
      Sex == "Female" ~ "Female",
      TRUE ~ NA_character_
    ),
    # Recode Political Party
    Political_Party_recode = case_when(
      `Political Party` == "Democrat" ~ "Democrat",
      `Political Party` == "Republican" ~ "Republican",
      `Political Party` == "Independent" ~ "Independent",
      `Political Party` == "Something else" ~ "Other party",
      TRUE ~ NA_character_
    )
  )

D_clean_complete <- D_clean |>
  filter(!is.na(Age_group),
         !is.na(Education_recode),
         !is.na(Income_group),
         !is.na(Race_recode),
         !is.na(Sex_recode),
         !is.na(Political_Party_recode))

dsgn <- svydesign(ids = ~1, data = D_clean_complete, weights = ~1)

pop_age_df <- population_proportions |> 
  filter(grepl("^Age", Characteristic)) |> 
  select(Characteristic, Population) |> 
  rename(Age_group = Characteristic, Freq = Population)

pop_edu_df <- population_proportions |> 
  filter(Characteristic %in% c("High school", "Some college", "Associates degree",
                                "Bachelors degree", "Masters degree", "Doctorate")) |> 
  select(Characteristic, Population) |> 
  rename(Education_recode = Characteristic, Freq = Population)

pop_income_df <- population_proportions |> 
  filter(grepl("^HH income", Characteristic)) |> 
  select(Characteristic, Population) |> 
  rename(Income_group = Characteristic, Freq = Population)

pop_race_df <- population_proportions |> 
  filter(Characteristic %in% c("White", "Black", "Asian", 
                               "American Indian or Alaska Native", "Other race")) |> 
  select(Characteristic, Population) |> 
  rename(Race_recode = Characteristic, Freq = Population)

pop_sex_df <- population_proportions |> 
  filter(Characteristic %in% c("Male", "Female")) |> 
  select(Characteristic, Population) |> 
  rename(Sex_recode = Characteristic, Freq = Population)

pop_party_df <- population_proportions |> 
  filter(Characteristic %in% c("Democrat", "Republican", "Independent", "Other party")) |> 
  select(Characteristic, Population) |> 
  rename(Political_Party_recode = Characteristic, Freq = Population)

# rake the survey design
raked_dsgn <- rake(design = dsgn,
                   sample.margins = list(~Age_group, ~Education_recode, ~Income_group, ~Race_recode, ~Sex_recode, ~Political_Party_recode),
                   population.margins = list(pop_age_df, pop_edu_df, pop_income_df, pop_race_df, pop_sex_df, pop_party_df))



spi_wtd_reg_list_given_data <- function(this_data){
    spi_SAI <- svyglm(standardized_policy_index ~ SAI_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, design = this_data)
    
    spi_Emissions <- svyglm(standardized_policy_index ~ Emissions_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, design = this_data)
    
    spi_all_four <- svyglm(standardized_policy_index ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, design = this_data)
    
    list(spi_SAI, spi_Emissions, spi_all_four)
    
}

spi_wtd_reg_list_wo_exclusions <- spi_wtd_reg_list_given_data(raked_dsgn)

main_result_table_from_wtd_reg_list <- function(wtd_reg_list){
  # adding a row to say: yes we have covariates
  rows <- tribble(~term, ~term, ~term, ~term, 
               "Covariates", "Yes", "Yes", "Yes")
  attr(rows, "position") <- 13 # put it at the bottom

  modelsummary::modelsummary(wtd_reg_list, 
                           stars = T, 
                           gof_map = c("nobs", "r.squared", "adj.r.squared"), 
                           coef_map = c("(Intercept)" = "Intercept", 
                                        "SAI_either" = "Provided SAI info", 
                                        "Emissions_either" = "Provided decarbonization info", 
                                        "ConditionSAI" = "Provided SAI info only", 
                                        "ConditionEmissions" = "Provided decarbonization info only", 
                                        "ConditionBoth" = "Provided both SAI and decarbonization info"), 
                           add_rows = rows,
                           width = c(4,1,1,1)) |> 
  tinytable::group_tt(j = list("DV: Index of support for mitigation policy" = 2:4))
}

main_result_table_from_reg_list(spi_wtd_reg_list_wo_exclusions)



## -----------------------------------------------------------------------------
#| label: fig-sai-on-individual-outcomes
#| fig-cap: "Average effect of providing SAI information on respondents' support for US taking individual policy steps"

x <- estimatr::lm_robust(I(as.integer(response_treaty)) ~ SAI_either + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

mod_list <- list("Sign international treaty to reduce emissions" = x,
                 "Require higher fuel efficiency" = update(x, I(as.integer(response_car_eff)) ~ .),
                 "Increase subsidies for renewable energy" = update(x, I(as.integer(response_renewables)) ~ .),
                 "Introduce a carbon tax" = update(x, I(as.integer(response_carbon_tax)) ~ .),
                 "Build more nuclear power plants" = update(x, I(as.integer(response_nuclear)) ~ .),
                 "Encourage individuals to use less energy" = update(x, I(as.integer(response_ind_use)) ~ .),
                 "Reduce emissions of factories and power plants" = update(x, I(as.integer(response_elec_emit)) ~ .),
                 "Use tax money to develop clean energy" = update(x, I(as.integer(response_clean_nrg)) ~ .))

tibble(name = names(mod_list),
       mod = mod_list) |> 
  mutate(tidied = map(mod, broom::tidy)) |> 
  unnest(tidied) |> 
  filter(term == "SAI_either") |> 
  mutate(name = fct_inorder(name)) |> 
  ggplot(aes(x = estimate, xmin = conf.low, xmax = conf.high, y = fct_rev(name))) + 
  geom_pointrange() + 
  geom_vline(xintercept = 0, lty = 3) + 
  labs(x = "Estimates with 95% Confidence Intervals", y = "")+
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"))


## -----------------------------------------------------------------------------
#| label: fig-info-on-individual-outcomes
#| fig-cap: "Average effect of each information treatment on respondents' support for US taking individual policy steps"

x <- estimatr::lm_robust(I(as.integer(response_treaty)) ~ Condition + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

mod_list <- list("Sign international treaty to reduce emissions" = x,
                 "Require higher fuel efficiency" = update(x, I(as.integer(response_car_eff)) ~ .),
                 "Increase subsidies for renewable energy" = update(x, I(as.integer(response_renewables)) ~ .),
                 "Introduce a carbon tax" = update(x, I(as.integer(response_carbon_tax)) ~ .),
                 "Build more nuclear power plants" = update(x, I(as.integer(response_nuclear)) ~ .),
                 "Encourage individuals to use less energy" = update(x, I(as.integer(response_ind_use)) ~ .),
                 "Reduce emissions of factories and power plants" = update(x, I(as.integer(response_elec_emit)) ~ .),
                 "Use tax money to develop clean energy" = update(x, I(as.integer(response_clean_nrg)) ~ .))

tibble(name = names(mod_list),
       mod = mod_list) |> 
  mutate(tidied = map(mod, broom::tidy)) |> 
  unnest(tidied) |> 
  filter(str_detect(term, "Condition")) |> 
  mutate(name = fct_inorder(name),
         term = str_remove(term, "Condition"),
         term = factor(term, levels = c("Emissions", "SAI", "Both"))) |> 
  ggplot(aes(x = estimate, xmin = conf.low, xmax = conf.high, y = fct_rev(name), col = term, pch = term)) + 
  geom_pointrange(position = position_dodge(width = -.35)) + 
  geom_vline(xintercept = 0, lty = 3) + 
  scale_color_manual(values = c("Emissions" = "#3B9AB2", "SAI" = "#E1AF00", "Both" = "#F98400")) +
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black")) +
  labs(x = "Estimates with 95% Confidence Intervals", y = "", pch = "", col = "")


## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-het-main
#| tbl-cap: "Heterogeneity in effect of SAI information on support for emission reduction policies"


het_reg_table_given_reg_list(spi_het_reg_list_wo_exclusions)



## ----main-mechanisms-table----------------------------------------------------
#| echo: false
#| label: tbl-sai-on-other-outcomes
#| tbl-cap: "Effect of SAI information on other attitudes"


other_attitudes_table_from_reg_list(other_attitudes_rl)


## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-other-outcomes-by-treatment-arm
#| tbl-cap: "Effect of each information treatment on other attitudes"


table_for_other_outcomes4(reg_list_other4)


## ----main-effect-heterogeneity-extra------------------------------------------
#| echo: false
D |> 
  mutate(mod = Affiliation == "Moderate",
         young = Age %in% 18:49,
         college = Education %in% c("Bachelor's degree (for example: BA, AB, BS)", "Doctorate degree (for example: PhD, EdD)", "Master's degree (for example: MA, MS, MEng, MEd, MSW, MBA)", "Professional degree (for example: MD, DDS, DVM, LLB, JD)"),
         poorer = `Household Income` %in% c("$10,000-$19,999", "$20,000-$29,999", "$30,000-$39,999", "$40,000-$49,999", "$50,000-$59,999", "$60,000-$69,999", "$70,000-$79,999")) -> Dpe2
         

spi_SAI_by_age <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*young + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = Dpe2)
spi_SAI_by_college <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*college + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = Dpe2)
spi_SAI_by_income <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*poorer + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = Dpe2)

spi_SAI_by_mod <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*mod + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = Dpe2)
spi_SAI_by_mod_att <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*I(attribution_quintile == 3) + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = Dpe2)
spi_SAI_by_mod_worry <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*I(cc_concern_pre == "Moderately concerned") + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = Dpe2)




## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-het-main-others
#| tbl-cap: "Heterogeneity in effect of SAI information on support for emission reduction policies by age, education, and income (exploratory analysis)"

rows <- tribble(~term, ~term, ~term, ~term,
               "Covariates", "Yes", "Yes", "Yes")
attr(rows, "position") <- 17 # put it at the bottom

modelsummary::modelsummary(list("By age" = spi_SAI_by_age, "By education" = spi_SAI_by_college, "By income" = spi_SAI_by_income), 
                           stars = T, 
                           gof_map = c("nobs", "r.squared", "adj.r.squared"), 
                           coef_map = c("(Intercept)" = "Intercept", 
                                        "SAI_either" = "Provided SAI info", 
                                        'modTRUE' = "Moderate",
                                        'SAI_either:modTRUE' = "SAI info X Moderate",
                                        'youngTRUE' = "Age below 50", 
                                        'SAI_either:youngTRUE' = "SAI info X Age below 50",
                                        "collegeTRUE" = "College graduate", 
                                        "SAI_either:collegeTRUE" = "SAI info X College graduate",
                                        "poorerTRUE" = "HH income < 80k", 
                                        "SAI_either:poorerTRUE" = "SAI info X HH income < 80k"), 
                           add_rows = rows) |>
  tinytable::group_tt(j = list("DV: Index of support for mitigation policy" = 2:4))



## -----------------------------------------------------------------------------
spi_SAI_by_affiliation_full <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

spi_SAI_by_concern_full <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*cc_concern_pre + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

spi_SAI_by_attribution_full <- estimatr::lm_robust(standardized_policy_index ~ SAI_either*attribution_quintile + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

# what could I show? effect at different levels. levels at different levels (by treatment group)
all_levels <- expand_grid(attribution_quintile = factor(unique(D$attribution_quintile), levels = levels(D$attribution_quintile)),
            Affiliation = factor(unique(D$Affiliation), levels = levels(D$Affiliation)),
            cc_concern_pre = factor(unique(D$cc_concern_pre), levels = levels(D$cc_concern_pre)),
            self_efficacy_pre = factor(unique(D$self_efficacy_pre), levels = levels(D$self_efficacy_pre)),
            SAI_either = c(0,1))


## ----preds-by-attribution-----------------------------------------------------
#| label: fig-preds-by-attribution
#| fig-cap: "Predicted support for mitigation policy by treatment status and pre-treatment attribution of climate change to human activity (other predictors set at midpoint)"

preds_by_attribution <- predict(spi_SAI_by_attribution_full, 
        newdata = all_levels,
        interval = "confidence")

all_levels |> 
  mutate(fit = preds_by_attribution$fit[,"fit"],
         lwr = preds_by_attribution$fit[,"lwr"],
         upr = preds_by_attribution$fit[,"upr"]) -> all_levels_augmented

all_levels_augmented |> 
  filter(Affiliation == "Moderate",
         cc_concern_pre == "Moderately concerned",
         self_efficacy_pre == "Neither agree nor disagree") |> 
  mutate(attribution_quintile = factor(attribution_quintile, levels = 1:5)) |> 
  ggplot(aes(x = attribution_quintile, y = fit, ymax = upr, ymin = lwr, col = factor(SAI_either), shape = factor(SAI_either))) + 
    scale_color_manual(values = c("0" = "#3B9AB2", "1" = "#E1AF00")) +
  geom_pointrange(position = position_dodge(width = .25)) + 
  labs(x = "Degree to which respondent attributes\nclimate change to human activities (quintiles)",
       y = "Predicted support for mitigation policy\n(standardized index)",
       col = "SAI information \nprovided",
       shape = "SAI information \nprovided") + 
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"))


## ----preds-by-affiliation-----------------------------------------------------
#| label: fig-preds-by-affiliation
#| fig-cap: "Predicted support for mitigation policy by treatment status and pre-treatment political affiliation (other predictors set at midpoint)"

preds_by_affiliation <- predict(spi_SAI_by_affiliation_full, 
        newdata = all_levels,
        interval = "confidence")

all_levels |> 
  mutate(fit = preds_by_affiliation$fit[,"fit"],
         lwr = preds_by_affiliation$fit[,"lwr"],
         upr = preds_by_affiliation$fit[,"upr"]) -> all_levels_augmented

all_levels_augmented |> 
  filter(attribution_quintile == 3,
         cc_concern_pre == "Moderately concerned",
         self_efficacy_pre == "Neither agree nor disagree") |> 
  mutate(Affiliation = factor(Affiliation, levels = c("Very conservative", "Conservative", "Moderate", "Liberal", "Very liberal"))) |> 
  ggplot(aes(x = Affiliation, y = fit, ymax = upr, ymin = lwr, col = factor(SAI_either), shape = factor(SAI_either))) + 
  geom_pointrange(position = position_dodge(width = .25)) + 
    scale_color_manual(values = c("0" = "#3B9AB2", "1" = "#E1AF00")) +
  labs(x = "Respondent's self-reported political affiliation",
       y = "Predicted support for mitigation policy\n(standardized index)",
       col = "SAI information\nprovided",
       shape = "SAI information\nprovided") + 
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black")) +
  theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust=1)) 


## ----preds-by-concern---------------------------------------------------------
#| label: fig-preds-by-cc-concern
#| fig-cap: "Predicted support for mitigation policy by treatment status and pre-treatment concern about climate change (other predictors set at midpoint)"

preds_by_concern <- predict(spi_SAI_by_concern_full, 
        newdata = all_levels,
        interval = "confidence")

all_levels |> 
  mutate(fit = preds_by_concern$fit[,"fit"],
         lwr = preds_by_concern$fit[,"lwr"],
         upr = preds_by_concern$fit[,"upr"]) -> all_levels_augmented

all_levels_augmented |> 
  filter(attribution_quintile == 3,
         Affiliation == "Moderate",
         self_efficacy_pre == "Neither agree nor disagree") |> 
  mutate(cc_concern_pre = factor(cc_concern_pre, levels = c("Not concerned at all", "Slightly concerned", "Moderately concerned", "Very concerned", "Extremely concerned"))) |> 
  ggplot(aes(x = cc_concern_pre, y = fit, ymax = upr, ymin = lwr, col = factor(SAI_either), shape = factor(SAI_either))) + 
  geom_pointrange(position = position_dodge(width = .25)) + 
      scale_color_manual(values = c("0" = "#3B9AB2", "1" = "#E1AF00")) +
  labs(x = "Respondent's concern about climate change",
       y = "Predicted support for mitigation policy\n(standardized index)",
       col = "SAI information\nprovided",
       shape = "SAI information\nprovided") + 
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black")) + 
  theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust=1)) 


## -----------------------------------------------------------------------------
spi_SAI_by_affiliation_full <- estimatr::lm_robust(standardized_worry_index ~ SAI_either*Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

spi_SAI_by_concern_full <- estimatr::lm_robust(standardized_worry_index ~ SAI_either*cc_concern_pre + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

spi_SAI_by_attribution_full <- estimatr::lm_robust(standardized_worry_index ~ SAI_either*attribution_quintile + Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D)

# what could I show? effect at different levels. levels at different levels (by treatment group)
all_levels <- expand_grid(attribution_quintile = factor(unique(D$attribution_quintile), levels = levels(D$attribution_quintile)),
            Affiliation = factor(unique(D$Affiliation), levels = levels(D$Affiliation)),
            cc_concern_pre = factor(unique(D$cc_concern_pre), levels = levels(D$cc_concern_pre)),
            self_efficacy_pre = factor(unique(D$self_efficacy_pre), levels = levels(D$self_efficacy_pre)),
            SAI_either = c(0,1))


## ----preds-by-attribution-worry-----------------------------------------------
#| label: fig-preds-by-attribution-worry
#| fig-cap: "Predicted concern about climate change by treatment status and pre-treatment attribution of climate change to human activity (other predictors set at midpoint)"

preds_by_attribution <- predict(spi_SAI_by_attribution_full, 
        newdata = all_levels,
        interval = "confidence")

all_levels |> 
  mutate(fit = preds_by_attribution$fit[,"fit"],
         lwr = preds_by_attribution$fit[,"lwr"],
         upr = preds_by_attribution$fit[,"upr"]) -> all_levels_augmented

all_levels_augmented |> 
  filter(Affiliation == "Moderate",
         cc_concern_pre == "Moderately concerned",
         self_efficacy_pre == "Neither agree nor disagree") |> 
  mutate(attribution_quintile = factor(attribution_quintile, levels = 1:5)) |> 
  ggplot(aes(x = attribution_quintile, y = fit, ymax = upr, ymin = lwr, col = factor(SAI_either), shape = factor(SAI_either))) + 
    scale_color_manual(values = c("0" = "#3B9AB2", "1" = "#E1AF00")) +
  geom_pointrange(position = position_dodge(width = .25)) + 
  labs(x = "Degree to which respondent attributes\nclimate change to human activities (quintiles)",
       y = "Predicted concern about climate change\n(standardized index)",
       col = "SAI information\nprovided",
       shape = "SAI information\nprovided") + 
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black"))


## ----preds-by-affiliation-worry-----------------------------------------------
#| label: fig-preds-by-affiliation-worry
#| fig-cap: "Predicted concern about climate change by treatment status and pre-treatment political affiliation (other predictors set at midpoint)"

preds_by_affiliation <- predict(spi_SAI_by_affiliation_full, 
        newdata = all_levels,
        interval = "confidence")

all_levels |> 
  mutate(fit = preds_by_affiliation$fit[,"fit"],
         lwr = preds_by_affiliation$fit[,"lwr"],
         upr = preds_by_affiliation$fit[,"upr"]) -> all_levels_augmented

all_levels_augmented |> 
  filter(attribution_quintile == 3,
         cc_concern_pre == "Moderately concerned",
         self_efficacy_pre == "Neither agree nor disagree") |> 
  mutate(Affiliation = factor(Affiliation, levels = c("Very conservative", "Conservative", "Moderate", "Liberal", "Very liberal"))) |> 
  ggplot(aes(x = Affiliation, y = fit, ymax = upr, ymin = lwr, col = factor(SAI_either), shape = factor(SAI_either))) + 
  geom_pointrange(position = position_dodge(width = .25)) + 
  scale_color_manual(values = c("0" = "#3B9AB2", "1" = "#E1AF00")) +
  labs(x = "Respondent's self-reported political affiliation",
       y = "Predicted concern about climate change\n(standardized index)",
       col = "SAI information\nprovided",
       shape = "SAI information\nprovided") + 
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black")) + 
  theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust=1)) 


## ----preds-by-concern-worry---------------------------------------------------
#| label: fig-preds-by-cc-concern-worry
#| fig-cap: "Predicted concern about climate change by treatment status and pre-treatment concern about climate change (other predictors set at midpoint)"

preds_by_concern <- predict(spi_SAI_by_concern_full, 
        newdata = all_levels,
        interval = "confidence")

all_levels |> 
  mutate(fit = preds_by_concern$fit[,"fit"],
         lwr = preds_by_concern$fit[,"lwr"],
         upr = preds_by_concern$fit[,"upr"]) -> all_levels_augmented

all_levels_augmented |> 
  filter(attribution_quintile == 3,
         Affiliation == "Moderate",
         self_efficacy_pre == "Neither agree nor disagree") |> 
  mutate(cc_concern_pre = factor(cc_concern_pre, levels = c("Not concerned at all", "Slightly concerned", "Moderately concerned", "Very concerned", "Extremely concerned"))) |> 
  ggplot(aes(x = cc_concern_pre, y = fit, ymax = upr, ymin = lwr, col = factor(SAI_either), shape = factor(SAI_either))) + 
  geom_pointrange(position = position_dodge(width = .25)) + 
  scale_color_manual(values = c("0" = "#3B9AB2", "1" = "#E1AF00")) +
  labs(x = "Respondent's concern about climate change",
       y = "Predicted concern about climate change\n(standardized index)",
       col = "SAI information\nprovided",
       shape = "SAI information\nprovided") + 
  theme(text = element_text(size = 10.5),
        legend.position = "top",
        legend.key = element_blank(),
        panel.grid.major = element_blank(),
        axis.text.x = element_text(size = 10.5, colour = "black"),
        axis.text.y = element_text(colour = "black"),
        plot.caption = element_text(size = 10.5, hjust = -.02),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black")) + 
  theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust=1)) 


## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-post-exclusion-balance
#| tbl-cap: "Omnibus balance tests (relative to control)"
#|
balance_reg_Emissions <- estimatr::lm_robust(I(Condition == "Emissions") ~ Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D_post_exclusions |> filter(Condition %in% c("Neither", "Emissions"))) 

balance_reg_SAI <- estimatr::lm_robust(I(Condition == "SAI") ~ Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D_post_exclusions |> filter(Condition %in% c("Neither", "SAI"))) 

balance_reg_Both <- estimatr::lm_robust(I(Condition == "Both") ~ Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D_post_exclusions |> filter(Condition %in% c("Neither", "Both"))) 

balance_reg_Emissions_full <- estimatr::lm_robust(I(Condition == "Emissions") ~ Affiliation + cc_concern_pre + attribution_quintile + self_efficacy_pre, data = D |> filter(Condition %in% c("Neither", "Emissions"))) 


fstat_p_val_from_reg <- function(reg){
  fstat <- summary(reg)$fstatistic
  1 - pf(fstat[1], fstat[2], fstat[3])
}

# adding a row at the bottom with the $p$-values on the F-tests
rows <- tribble(~term, ~term, ~term, ~term, ~term,
                # see function for getting F-test $p$-value from regression output 
               "$p$-value from F-test", fstat_p_val_from_reg(balance_reg_Emissions), fstat_p_val_from_reg(balance_reg_SAI), fstat_p_val_from_reg(balance_reg_Both), fstat_p_val_from_reg(balance_reg_Emissions_full))
attr(rows, "position") <- 37 # put it at the bottom

modelsummary::modelsummary(list("Emissions" = balance_reg_Emissions, "SAI" = balance_reg_SAI, "Both" = balance_reg_Both, "Emissions w/ exclusions" = balance_reg_Emissions_full), stars = T, gof_map = c("nobs"), add_rows = rows,
                           width = c(7,1.75,1.75,1.75,2),
                           coef_map = c("(Intercept)" = "Intercept",
                                        "AffiliationVery conservative" = "Very conservative",
                                        "AffiliationConservative" = "Conservative",
                                        "AffiliationLiberal" = "Liberal",
                                        "AffiliationVery liberal" = "Very liberal",
                                        "cc_concern_preNot concerned at all" = "Not concerned at all about CC",
                                        "cc_concern_preSlightly concerned" = "Slightly concerned about CC",
                                        "cc_concern_preVery concerned" = "Very concerned about CC",
                                        "cc_concern_preExtremely concerned" = "Extremely concerned about CC",
                                        "attribution_quintile1" = "Humans responsible for CC: Lowest",
                                        "attribution_quintile2" = "Humans responsible for CC: Med low",
                                        "attribution_quintile4" = "Humans responsible for CC: Med high",
                                        "attribution_quintile5" = "Humans responsible for CC: High",
                                        "self_efficacy_preStrongly disagree" = "Can do something about CC: Strongly disagree",
                                        "self_efficacy_preSomewhat disagree" = "Can do something about CC: Somewhat disagree",
                                        "self_efficacy_preSomewhat agree" = "Can do something about CC: Somewhat agree",
                                        "self_efficacy_preStrongly agree" = "Can do something about CC: Strongly agree")) |>  
  tinytable::group_tt(j = list("DV: Treated" = 2:5)) |> 
  tinytable::style_tt(fontsize = .75, 
                      bootstrap_css = "padding-right: .05em; padding-top: .05em;",
                      tabularray_inner = "rowsep={.05em}, colsep = {.1em}")


## ----main-no-exclusions-------------------------------------------------------
#| echo: false
#| label: tbl-main-results-w-exclusions
#| tbl-cap: "Effect of information treatments on support for emission reduction policies (with sample exclusions)"
spi_reg_list_w_exclusions <- spi_reg_list_given_data(D_post_exclusions)
main_result_table_from_reg_list(spi_reg_list_w_exclusions) |> 
  tinytable::style_tt(fontsize = .75) 
 #                     bootstrap_css = "padding-right: .05em; padding-top: .05em;",
#                      tabularray_inner = "rowsep={.05em}, colsep = {.1em}")


## -----------------------------------------------------------------------------
#| label: tbl-het-main-w-exclusions
#| tbl-cap: "Heterogeneity in effect of SAI information on support for emission reduction policies (with sample exclusions)"
spi_het_reg_list_w_exclusions <- spi_het_reg_list_given_data(D_post_exclusions)
het_reg_table_given_reg_list(spi_het_reg_list_w_exclusions)


## ----main-mechanisms-w-exclusions---------------------------------------------
#| echo: false
#| label: tbl-sai-on-other-outcomes-w-exclusions
#| tbl-cap: "Effect of SAI information on other attitudes (with sample exclusions)"

other_attitudes_rl <- other_attitudes_reg_list(D_post_exclusions)
other_attitudes_table_from_reg_list(other_attitudes_rl)


## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-other-outcomes-by-treatment-arm-w-exclusions
#| tbl-cap: "Effect of each information treatment on other attitudes (with sample exclusions)"

reg_list_other4 <- reg_list_other_outcomes4(D_post_exclusions)
table_for_other_outcomes4(reg_list_other4)


## -----------------------------------------------------------------------------
#| echo: false
#| label: tbl-pre-reg-report
#| tbl-cap: "Pre-registration reporting table"

tribble(~` `, ~`Specified in pre-registration?`, ~`Reported in manuscript?`, ~`Deviations`,
        "Sampling", "Yes", "Yes (pp 9-10)", "",
        "Sample exclusions", "Yes", "Yes (pp 9-10)", "Results using original exclusion plan appear in Appendix; manuscript explains that we analyze the full sample to satisfy journal requirements (explained pp 9-10 in manuscript)",
        "Experimental conditions", "Yes", "Yes (pp 7-8)","",
        "Observed measure 1: Normalized index of support for emissions reduction policy", "Yes", "Yes (pg 7)", "",
        "Observed measures 2-5: Worry about climate change, perceived threat from tech responses to CC, belief in efficacy of emissions reductions, belief in 'techno fix'", "Yes", "Yes (pp 8-9)", "",
        "Hypotheses", "NA", "NA", "Our PAP contains no hypotheses. We do specify a measurement strategy for several causal estimands. See next several rows.",
        "Measuring effect of SAI information on index of policy preferences", "Yes", "Yes (section 5.2)", "None",
        "Measuring heterogeneous effects of SAI information on index of policy preferences", "Yes", "Yes (section 5.3)", "None",
        "Measuring effect of SAI information on other attitudes", "Yes", "Yes (section 5.4)", "None",
        "Were there studies included in pre-registration that are not reported in the manuscript? (If yes, explain)", "No", "NA", "") |> 
  tinytable::tt(width = c(2,1,1,2))



